package cn.com.dycc.infomation_center.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.infomation_center.param.Pb_Party_InformationParam;
import cn.com.dycc.infomation_center.service.Pb_Party_InformationNotFoundException;
import cn.com.dycc.infomation_center.service.Pb_Party_InformationService;
import cn.com.dycc.util.JsonObjectResult;


@Controller
@RequestMapping("/infomation_center/pb_party_information")
public class Pb_Party_InformationController extends BaseController{

	@Resource
	private Pb_Party_InformationService pb_Party_InformationService;
	
	/**
	 * 新增资讯信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addPb_Party_Information(Pb_Party_InformationParam param,HttpSession session,HttpServletRequest request){
		
		int d=pb_Party_InformationService.addPb_Party_Information(param,request);
		String flag="成功导入数据条数为:"+d;
		return new JsonObjectResult(flag);		
	}
	
	/**
	 * 修改资讯信息
	 * @param param
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updatePb_Party_Information(Pb_Party_InformationParam param,HttpServletRequest request,HttpSession session){
		
		int d=pb_Party_InformationService.updatePb_Party_Information(param,request);
		String flag="成功更新数据条数为:"+d;
		return new JsonObjectResult(flag);
	}
	
	/**
	 * 删除资讯信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deletePb_Party_Information(HttpServletRequest request){
		String []attrStrs=request.getParameterValues("info_id");
		int d=pb_Party_InformationService.deletePb_Party_Information(attrStrs,request);
		String flag="成功删除数据条数为:"+d;
		return new JsonObjectResult(flag);
	}
	
	/**
	 * 查询自己所创建的资讯信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/list.do")
	@ResponseBody
	public JsonObjectResult findPb_Party_Information(Pb_Party_InformationParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		String id=(String)session.getAttribute("id");
		String org_id=(String)session.getAttribute("org_id");
		param.setOpt_user_id(id);
		param.setOrg_id(org_id);
		
		JsonObjectResult result=pb_Party_InformationService.findPb_Party_InformationByParam(param,request);
		
		return result;
	}
	
	/**
	 * 查询自己所在的组织id下的所有资讯信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/listAll.do")
	@ResponseBody
	public JsonObjectResult findAllPb_Party_Information(Pb_Party_InformationParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		String user_id=(String)session.getAttribute("id");
		String org_id=(String)session.getAttribute("org_id");
		System.out.println("user_id:"+user_id);
		System.out.println("org_id:"+org_id);
		param.setOrg_id(org_id);
		JsonObjectResult result=pb_Party_InformationService.findPb_Party_InformationByParam(param,request);
		
		return result;
	}
	
	/**
	 * 提供给app资讯首页展示的资讯信息
	 * @param session
	 * @param request
	 * @return
	 * @throws Pb_Party_InformationNotFoundException
	 * @throws IOException
	 */
	@RequestMapping("/appIndex.do")
	@ResponseBody
	public JsonObjectResult findNewPb_Party_Information(HttpSession session,HttpServletRequest request) throws Pb_Party_InformationNotFoundException, IOException{
		
		JsonObjectResult result=pb_Party_InformationService.findNewPb_Party_Information(request);
		
		return result;
	}
	
	
}
